package com.wandian.texas.entity;

/**
 * @author long
 * @Create 2012-11-4 下午3:42:34
 * @QQ 108232706
 * @version 1.0
 * @description WinCardEntity
 */
public class WinCardEntity {
	//	public int seatId;
	/**
	 * 高牌|一对|两对|三条|顺子|同花|葫芦|四条|同花顺|皇家同花顺
	 */
	private int type;
	//	public int isWin;
	public int huase;
	//	public CardVo[] arrCards = new CardVo[10];
	//	public CardVo[] arrCards2 = new CardVo[10];
	public CardVo[] arrMaxHandCards = new CardVo[5];

	public WinCardEntity() {
		for (int i = 0; i < arrMaxHandCards.length; i++) {
			arrMaxHandCards[i] = new CardVo();
		}
	}

//	/**
//	 * 拷贝牌
//	 * @param index
//	 * @param card
//	 */
//	public void MaxHandCards(int index, CardVo card) {
//		arrMaxHandCards[index].cardStr = card.cardStr;
//		arrMaxHandCards[index].num = card.num;
//		arrMaxHandCards[index].huase = card.huase;
//	}

	public void clearHandCards() {
		for (int i = 0; i < arrMaxHandCards.length; i++) {
			arrMaxHandCards[i].num = 0;
		}
	}

	/**
	 * 标识当前牌有效长
	 */
	public int CardLen;

	public void clear() {
		for (int i = 0; i < arrMaxHandCards.length; i++) {
			arrMaxHandCards[i].num = 0;
		}
		type = 0;
		//		isWin = 0;
	}

	// public ArrayList<CardVo> arrCards;
	// public ArrayList<CardVo> arrCards2;
	// public ArrayList<CardVo> arrMaxHandCards;
	/**
	 * 4条里单独一张
	 */
	//	private CardVo singleCard;

	// public WinCardEntity(int _type, int _huase, ArrayList<CardVo> _arrCards,
	// ArrayList<CardVo> _arrMaxHandCards) {
	// this.huase = _huase;
	// this.arrCards = _arrCards;
	// this.arrMaxHandCards = _arrMaxHandCards;
	// this.setType(_type);
	// }

	public String getMaxCards() {
		String strMaxCards = "";
		for (int i = 0; i < 5; i++) {
			strMaxCards += this.getCard(i);
		}
		return strMaxCards;
	}

	// public WinCardEntity(int _type, ArrayList<CardVo> _arrCards,
	// ArrayList<CardVo> _arrCards2, ArrayList<CardVo> _arrMaxHandCards) {
	// this.arrCards = _arrCards;
	// this.arrCards2 = _arrCards2;
	// this.arrMaxHandCards = _arrMaxHandCards;
	// this.setType(_type);
	// }

	//	private void setA(ArrayList<CardVo> _arrCards) {
	//		if (_arrCards != null) {
	//			for (CardVo c : _arrCards) {
	//				if (c.num == 1)
	//					c.num = 14;
	//			}
	//		}
	//	}

	//	private void setA() {
	//		for (CardVo c : this.arrCards) {
	//			if (c.num == 1)
	//				c.num = 14;
	//		}
	//		for (CardVo c : this.arrCards2) {
	//			if (c.num == 1)
	//				c.num = 14;
	//		}
	//		for (CardVo c : this.arrMaxHandCards) {
	//			if (c.num == 1) {
	//				// 顺序交换
	//			}
	//		}
	//		// for (int i = 0; i < this.arrMaxHandCards.length; i++) {
	//		// c = this.arrMaxHandCards[i];
	//		// if (c.num == 1) {
	//		// c.num = 14;
	//		// this.arrMaxHandCards.remove(c);
	//		// this.arrMaxHandCards.add(0, c);
	//		// }
	//		// }
	//	}

	// public WinCardEntity(int _type, ArrayList<CardVo> _arrCards,
	// ArrayList<CardVo> _arrCards2, ArrayList<CardVo> _arrMaxHandCards, CardVo
	// _singleCard) {
	// this.setType(_type);
	// this.arrCards = _arrCards;
	// this.arrCards2 = _arrCards2;
	// this.arrMaxHandCards = _arrMaxHandCards;
	// this.singleCard = _singleCard;
	// }

	//	public int singleCardValue() {
	//		return singleCard.num;
	//	}
	//
	//	public int maxCards1Value() {
	//		return arrCards[0].num;
	//	}
	//
	//	public int maxCards1Value(int index) {
	//		return arrCards[index].num;
	//	}
	//
	//	public int maxCards2Value() {
	//		return arrCards2[0].num;
	//	}

	//	public int maxHandCardsValue() {
	//		return arrMaxHandCards[0].num;
	//	}

	public int getHandCardsValue(int index) {
		return arrMaxHandCards[index].num;
		/*
		// 比较大小值
		int findCount = 0;
		switch (getType()) {
		// 皇家同花顺 type:9 isWin:0 huase:4 arrCard:arr1
		// 长度:4[黑桃14][黑桃13][黑桃12][黑桃11]最大手牌:长度:6[黑桃14][黑桃13][黑桃12][黑桃11][黑桃10][黑桃1]
		case 9:
		case 8:
			// 同花顺 type:8 isWin:0 huase:4 arrCard:arr1
			// 长度:5[黑桃13][黑桃12][黑桃11][黑桃10][黑桃9]最大手牌:长度:5[黑桃13][黑桃12][黑桃11][黑桃10][黑桃9]
		case 5:
			// 同花 type:5 isWin:0 huase:3 arrCard:arr1
			// 长度:5[红桃13][红桃10][红桃7][红桃5][红桃3]最大手牌:长度:5[红桃13][红桃10][红桃7][红桃5][红桃3]
		case 4:
			// 顺子 type:4 isWin:0 huase:-1 arrCard:arr1
			// 长度:5[黑桃8][黑桃7][红桃6][梅花5][方块4]最大手牌:长度:5[黑桃8][黑桃7][红桃6][梅花5][方块4]
		case 0:
			// 高牌 type:0 isWin:0 huase:0 arrCard:arr1
			// 长度:5[方块11][黑桃7][黑桃6][红桃5][方块2]最大手牌:长度:5[方块11][黑桃7][黑桃6][红桃5][方块2]
			return arrCards[0].num;
		case 7:
			// 四条 type:7 isWin:0 huase:0 arrCard:arr1
			// 长度:4[方块6][梅花6][红桃6][黑桃6]最大手牌:长度:5[方块6][梅花6][红桃6][黑桃6][方块4]
			if (index < 4) {
				return arrCards[index].num;
			}
			return singleCard.num;
		case 6:
			// 葫芦 type:6 isWin:0 huase:0 arrCard:arr1
			// 长度:3[方块8][梅花8][红桃8]arr2:长度:2[梅花11][红桃11]最大手牌:长度:5[梅花11][红桃11][方块8][梅花8][红桃8]
			if (index < 3) {
				return arrCards[index].num;
			}
			return arrCards2[index - 3].num;
		case 3:
			// 三条 type:3 isWin:0 huase:0 arrCard:arr1
			// 长度:3[方块8][梅花8][红桃8]最大手牌:长度:5[黑桃11][黑桃10][方块8][梅花8][红桃8]
			if (index >= 0 && index <= 2) {
				return arrCards[index].num;
			}
			if (index > 4) {
				return 0;
			}
			int threeindex = this.indexOf(arrCards[0]);

			for (int i = 0; i < arrMaxHandCards.length; i++) {
				if (i >= threeindex && i <= threeindex + 2) {
					continue;
				}
				findCount++;
				if (index - 2 == findCount) {
					return arrMaxHandCards[i].num;
				}
			}

		case 2:

			// 两对 type:2 isWin:0 huase:0 arrCard:arr1
			// 长度:2[黑桃10][红桃10]arr2:长度:2[方块2][梅花2]最大手牌:长度:5[黑桃10][红桃10][黑桃7][方块2][梅花2]
			// <------------
			switch (index) {
			case 0:
			case 1:
				return arrCards[index].num;
			case 2:
			case 3:
				return arrCards2[index - 2].num;
			case 4:
				int twoindex1 = this.indexOf(arrCards[0]);
				int twoindex2 = this.indexOf(arrCards2[0]);
				for (int i = 0; i < arrMaxHandCards.length; i++) {
					if ((i >= twoindex1 && i <= twoindex1 + 1) || (i >= twoindex2 && i <= twoindex2 + 1)) {
						continue;
					}
					return arrMaxHandCards[i].num;
				}
			default:
				break;
			}
			return 0;
			// ----------->
		case 1:
			// 一对 type:1 isWin:0 huase:0 arrCard:arr1
			// 长度:2[梅花8][红桃8]最大手牌:长度:5[方块11][梅花8][红桃8][黑桃7][红桃4]
			// <------------
			switch (index) {
			case 0:
			case 1:
				return arrCards[index].num;
			case 2:
			case 3:
			case 4:
				int twoindex1 = this.indexOf(arrCards[0]);
				for (int i = 0; i < arrMaxHandCards.length; i++) {
					if ((i >= twoindex1 && i <= twoindex1 + 1)) {
						continue;
					}
					findCount++;
					if (index - 1 == findCount)
						return arrMaxHandCards[i].num;
				}
			default:
				break;
			}
			return 0;
			// ------------>
		default:
			break;
		}
		return 0;*/
	}

	public int indexOf(CardVo cardVo) {
		// return arrMaxHandCards.indexOf(cardVo);
		for (int i = 0; i < arrMaxHandCards.length; i++) {
			if (arrMaxHandCards[i] == cardVo)
				return i;
		}
		return -1;
	}

	public String getCard(int index) {
		return arrMaxHandCards[index].cardStr;
		/*
		// 比较大小值
		int findCount = 0;
		switch (getType()) {
		// 皇家同花顺 type:9 isWin:0 huase:4 arrCard:arr1
		// 长度:4[黑桃14][黑桃13][黑桃12][黑桃11]最大手牌:长度:6[黑桃14][黑桃13][黑桃12][黑桃11][黑桃10][黑桃1]
		case 9:
		case 8:
			// 同花顺 type:8 isWin:0 huase:4 arrCard:arr1
			// 长度:5[黑桃13][黑桃12][黑桃11][黑桃10][黑桃9]最大手牌:长度:5[黑桃13][黑桃12][黑桃11][黑桃10][黑桃9]
		case 5:
			// 同花 type:5 isWin:0 huase:3 arrCard:arr1
			// 长度:5[红桃13][红桃10][红桃7][红桃5][红桃3]最大手牌:长度:5[红桃13][红桃10][红桃7][红桃5][红桃3]
		case 4:
			// 顺子 type:4 isWin:0 huase:-1 arrCard:arr1
			// 长度:5[黑桃8][黑桃7][红桃6][梅花5][方块4]最大手牌:长度:5[黑桃8][黑桃7][红桃6][梅花5][方块4]
		case 0:
			// 高牌 type:0 isWin:0 huase:0 arrCard:arr1
			// 长度:5[方块11][黑桃7][黑桃6][红桃5][方块2]最大手牌:长度:5[方块11][黑桃7][黑桃6][红桃5][方块2]
			return arrCards[index].cardStr;
		case 7:
			// 四条 type:7 isWin:0 huase:0 arrCard:arr1
			// 长度:4[方块6][梅花6][红桃6][黑桃6]最大手牌:长度:5[方块6][梅花6][红桃6][黑桃6][方块4]
			if (index < 4) {
				return arrCards[index].cardStr;
			}
			return singleCard.cardStr;
		case 6:
			// 葫芦 type:6 isWin:0 huase:0 arrCard:arr1
			// 长度:3[方块8][梅花8][红桃8]arr2:长度:2[梅花11][红桃11]最大手牌:长度:5[梅花11][红桃11][方块8][梅花8][红桃8]
			if (index < 3) {
				return arrCards[index].cardStr;
			}
			return arrCards2[index - 3].cardStr;
		case 3:
			// 三条 type:3 isWin:0 huase:0 arrCard:arr1
			// 长度:3[方块8][梅花8][红桃8]最大手牌:长度:5[黑桃11][黑桃10][方块8][梅花8][红桃8]
			if (index >= 0 && index <= 2) {
				return arrCards[index].cardStr;
			}
			if (index > 4) {
				return "";
			}
			int threeindex = this.indexOf(arrCards[0]);
			for (int i = 0; i < arrMaxHandCards.length; i++) {
				if (i >= threeindex && i <= threeindex + 2) {
					continue;
				}
				findCount++;
				if (index - 2 == findCount) {
					return arrMaxHandCards[i].cardStr;
				}
			}

		case 2:

			// 两对 type:2 isWin:0 huase:0 arrCard:arr1
			// 长度:2[黑桃10][红桃10]arr2:长度:2[方块2][梅花2]最大手牌:长度:5[黑桃10][红桃10][黑桃7][方块2][梅花2]
			// <------------
			switch (index) {
			case 0:
			case 1:
				return arrCards[index].cardStr;
			case 2:
			case 3:
				return arrCards2[index - 2].cardStr;
			case 4:
				int twoindex1 = this.indexOf(arrCards[0]);
				int twoindex2 = this.indexOf(arrCards2[0]);
				for (int i = 0; i < arrMaxHandCards.length; i++) {
					if ((i >= twoindex1 && i <= twoindex1 + 1) || (i >= twoindex2 && i <= twoindex2 + 1)) {
						continue;
					}
					return arrMaxHandCards[i].cardStr;
				}
			default:
				break;
			}
			return "";
			// ----------->
		case 1:
			// 一对 type:1 isWin:0 huase:0 arrCard:arr1
			// 长度:2[梅花8][红桃8]最大手牌:长度:5[方块11][梅花8][红桃8][黑桃7][红桃4]
			// <------------
			switch (index) {
			case 0:
			case 1:
				return arrCards[index].cardStr;
			case 2:
			case 3:
			case 4:
				int twoindex1 = this.indexOf(arrCards[0]);
				for (int i = 0; i < arrMaxHandCards.length; i++) {
					if ((i >= twoindex1 && i <= twoindex1 + 1)) {
						continue;
					}
					findCount++;
					if (index - 1 == findCount)
						return arrMaxHandCards[i].cardStr;
				}
			default:
				break;
			}
			return "";
			// ----------->

		default:
			break;
		}
		return "";*/
	}

	@Override
	public String toString() {
		return " type:" + getType() + " huase:" + huase + " arrCard:" + getMaxCards();
		/*StringBuilder sb = new StringBuilder();
		if (arrCards != null) {
			sb.append("arr1: ");
			for (CardVo card : arrCards) {
				sb.append(card.toString());
			}
		}
		if (arrCards2 != null) {
			sb.append("---->>arr2: ");
			for (CardVo card : arrCards2) {
				sb.append(card.toString());
			}
		}
		if (arrMaxHandCards != null) {
			sb.append("======>>手牌:");
			for (CardVo card : arrMaxHandCards) {
				sb.append(card.toString());
			}
		}
		return String.format(" type:%s %s isWin:%s huase:%s arrCard:%s", getType(), GamePool.arrCardType[getType()], isWin, huase, sb);*/
	}

	//	public CardVo getSingleCard() {
	//		return singleCard;
	//	}
	//
	//	public void setSingleCard(CardVo singleCard) {
	//		this.singleCard = singleCard;
	//	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}
	/*public void setType(int type) {
		this.type = type;
		// 比较大小值
		switch (this.type) {
		// 皇家同花顺 type:9 isWin:0 huase:4 arrCard:arr1
		// 长度:4[黑桃14][黑桃13][黑桃12][黑桃11]最大手牌:长度:6[黑桃14][黑桃13][黑桃12][黑桃11][黑桃10][黑桃1]
		case 9:
			break;
		case 8:
			// 同花顺 type:8 isWin:0 huase:4 arrCard:arr1
			// 长度:5[黑桃13][黑桃12][黑桃11][黑桃10][黑桃9]最大手牌:长度:5[黑桃13][黑桃12][黑桃11][黑桃10][黑桃9]
			break;
		case 7:
			// 四条 type:7 isWin:0 huase:0 arrCard:arr1
			// 长度:4[方块6][梅花6][红桃6][黑桃6]最大手牌:长度:5[方块6][梅花6][红桃6][黑桃6][方块4]
			break;
		case 6:
			// 葫芦 type:6 isWin:0 huase:0 arrCard:arr1
			// 长度:3[方块8][梅花8][红桃8]arr2:长度:2[梅花11][红桃11]最大手牌:长度:5[梅花11][红桃11][方块8][梅花8][红桃8]
			break;
		case 5:
			// 同花 type:5 isWin:0 huase:3 arrCard:arr1
			// 长度:5[红桃13][红桃10][红桃7][红桃5][红桃3]最大手牌:长度:5[红桃13][红桃10][红桃7][红桃5][红桃3]
			break;
		case 4:
			// 顺子 type:4 isWin:0 huase:-1 arrCard:arr1
			// 长度:5[黑桃8][黑桃7][红桃6][梅花5][方块4]最大手牌:长度:5[黑桃8][黑桃7][红桃6][梅花5][方块4]
			break;
		case 3:
			// 三条 type:3 isWin:0 huase:0 arrCard:arr1
			// 长度:3[方块8][梅花8][红桃8]最大手牌:长度:5[黑桃11][黑桃10][方块8][梅花8][红桃8]
			setA();
			break;
		case 2:
			// 两对 type:2 isWin:0 huase:0 arrCard:arr1
			// 长度:2[黑桃10][红桃10]arr2:长度:2[方块2][梅花2]最大手牌:长度:5[黑桃10][红桃10][黑桃7][方块2][梅花2]
			setA();
			CardVo c;
			if (this.arrCards[0].num < this.arrCards2[0].num) {
				// ArrayList<CardVo> temp = this.arrCards;
				// this.arrCards = this.arrCards2;
				// this.arrCards2 = temp;
				for (int i = 0; i < arrCards.length; i++) {
					c = arrCards[i];
					arrCards[i] = arrCards2[i];
					arrCards2[i] = c;
				}
			}
			break;
		case 1:
			// 一对 type:1 isWin:0 huase:0 arrCard:arr1
			// 长度:2[梅花8][红桃8]最大手牌:长度:5[方块11][梅花8][红桃8][黑桃7][红桃4]
		case 0:
			// 高牌 type:0 isWin:0 huase:0 arrCard:arr1
			// 长度:5[方块11][黑桃7][黑桃6][红桃5][方块2]最大手牌:长度:5[方块11][黑桃7][黑桃6][红桃5][方块2]
			setA();
		default:
			break;
		}
	}*/

}
